import 'package:flutter/material.dart';
import 'package:mobile_app.core/core/presentation/theme/styles.dart';

part 'single_collection_page_styles.dart';

part 'single_collection_page_text_theme.dart';

class SingleCollectionPageTheme extends InheritedTheme {
  SingleCollectionPageTheme({
    required Brightness brightness,
    required super.child,
    super.key,
  })  : _brightness = brightness,
        _data = _buildThemeData(
          brightness: brightness,
        );

  final Brightness _brightness;
  final SingleCollectionPageThemeData _data;

  static SingleCollectionPageThemeData _buildThemeData({
    required Brightness brightness,
  }) {
    return switch (brightness) {
      Brightness.dark => SingleCollectionPageThemeData.dark(),
      Brightness.light => SingleCollectionPageThemeData.light(),
    };
  }

  static SingleCollectionPageThemeData of(BuildContext context) {
    final inheritedTheme = context.dependOnInheritedWidgetOfExactType<SingleCollectionPageTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<SingleCollectionPageTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return SingleCollectionPageTheme(
      brightness: _brightness,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(SingleCollectionPageTheme oldWidget) {
    return _brightness != oldWidget._brightness;
  }
}

class SingleCollectionPageThemeData {
  const SingleCollectionPageThemeData._internal({
    required this.textTheme,
  });

  factory SingleCollectionPageThemeData.light() {
    return SingleCollectionPageThemeData._internal(
      textTheme: SingleCollectionPageTextTheme.light(),
    );
  }

  factory SingleCollectionPageThemeData.dark() {
    return SingleCollectionPageThemeData._internal(
      textTheme: SingleCollectionPageTextTheme.dark(),
    );
  }

  final SingleCollectionPageTextTheme textTheme;
}
